package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.service.RoleService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;


@RestController
@RequestMapping("/role")
public class RoleConteoller {
    @Reference
    RoleService roleService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return roleService.findPage(queryPageBean);
    }

    @RequestMapping("/findMenuByRoleId")
    public Result findMenuByRoleId(Integer id) {
        List<Menu> menus = roleService.findMenuByRoleId(id);
        return Result.success("", menus);
    }

    @RequestMapping("/findPermissionByRoleId")
    public Result findPermissionByRoleId(Integer id) {
        Set<Permission> permissions = roleService.findPermissionByRoleId(id);
        return Result.success("", permissions);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id) {
        return roleService.deleteById(id);
    }
    @RequestMapping("/findAll")
    public Result findAll() {
        Role role = roleService.findAll();
        return Result.success("", role);
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Role role) {
        roleService.add(role);
        return Result.success("新增角色完成");
    }
}
